package com.mf.controller;

import com.mf.mult.DataSource;
import com.mf.mult.DataSourceType;
import com.mf.mult.DynamicDataSourceContextHolder;
import com.mf.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: lmf
 * @Create: 2025/3/27 10:20
 * @module 数据源切换测试
 */
@RestController
@RequestMapping("test")
public class TestController {
    @Operation(summary = "使用数据源-LOCAL")
    @GetMapping("dataSwitchToLOCAL")
    @DataSource(value = DataSourceType.LOCAL)
    public Result<String> dataSwitchToLOCAL() {
        return Result.success(DynamicDataSourceContextHolder.getDataSourceType());
    }

    @Operation(summary = "使用数据源-REMOTE")
    @GetMapping("dataSwitchToREMOTE")
    @DataSource(value = DataSourceType.REMOTE)
    public Result<String> dataSwitchToREMOTE() {
        return Result.success(DynamicDataSourceContextHolder.getDataSourceType());
    }
}
